import { Component, PureComponent } from 'react';

Component.prototype.formatCopper = function (value) {
  if (value === null || value === 'undefined' || value === 'null') {
    return '-';
  }
  return parseFloat(value).toFixed(3);
};

Component.prototype.formatCopper1 = function (value, precision) {
  if (value === undefined || value === 'undefined' || value === null || value === 'null') {
    return '-';
  }
  if (isNaN(value)) {
    return '-';
  }
  return parseFloat(value).toFixed(precision);
};

PureComponent.prototype.formatCopper = function (value) {
  if (value === undefined || value === 'undefined' || value.length < 1) {
    return '0.00';
  }
  return parseFloat(value).toFixed(3);
};

if ('serviceWorker' in navigator) {
  // unregister service worker
  const { serviceWorker } = navigator;

  if (serviceWorker.getRegistrations) {
    serviceWorker.getRegistrations().then((sws) => {
      sws.forEach((sw) => {
        sw.unregister();
      });
    });
  }

  serviceWorker.getRegistration().then((sw) => {
    if (sw) sw.unregister();
  }); // remove all caches

  if (window.caches && window.caches.keys) {
    caches.keys().then((keys) => {
      keys.forEach((key) => {
        caches.delete(key);
      });
    });
  }
}
